home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Graphics / convd / conv2.p < prev    next >
Text File  |  2000-05-17  |  7KB  |  257 lines

  1. ; Project : Grafik Converter Client
  2. ;  
  3. ; It`s forbidden to use this software for commercial use!
  4. ;
  5. ; (c) 2000 Cyborg 
  6.  
  7.     {* Include sys:coder/preass/Options.p *}
  8.  
  9.     {* String: Version="$VER: Grafik Converter client (C) CYBORG 2000"*}
  10.  
  11.     {* Structure sockaddr_in(),sin_len(BYTE),sin_family(BYTE),sin_port(WORD)
  12.                  sin_addr(LONG),sin_zero[8]*}
  13.     
  14.     {* Structure Hostent,H_name(CHAR),h_aliases(APTR),h_addrtype(LONG)
  15.                  h_length(LONG),H_addr_list(CHAR)*}
  16.  
  17.     {* Structure Scaleoperators(),Type(LONG),XPixel(LONG),YPixel(LONG),Colors(LONG)
  18.                  Aktion1(BYTE),Data1(BYTE),Aktion2(BYTE),Data2(BYTE)
  19.                  Aktion3(BYTE),Data3(BYTE),Aktion4(BYTE),Data4(BYTE)
  20.                  Aktion5(BYTE),Data5(BYTE)*}
  21.  
  22.     {* IncBlock: Puffer,2048*}
  23.  
  24.     {* Const AF_INET=2,INADDR_ANY=0
  25.              Sock_STREAM=1
  26.              FIONBIO=$8004667e*}
  27.  
  28.     {* incVar: Addr,Zeiger,Filelen*}
  29.  
  30.     {* NewProc=CountString[String][A0]*}
  31.  
  32. ; Effects    
  33.  
  34.     FlipX=0             ; set data to zero
  35.     FlipY=1             ; set data to zero
  36.     GreyScale=2         ; set data to zero
  37.     Highlight=3         ; needs data 0-255 set
  38.     Negative=4          ; set data to zero
  39.     Random=5            ; needs data 0-255 set
  40.     RIOP=6              ; set data to zero
  41.     RollX=7             ; needs data 0-127 set
  42.     RollY=8             ; needs data 0-127 set
  43.     Pixelise=9          ; needs data 0-255 set
  44.     Shadow=10           ; needs data 0-255 set
  45.     
  46. ; Convoles 
  47.  
  48.     BlurHigh=128
  49.     BlurLow=129
  50.     Chisel=130
  51.     Cross=131
  52.     Diagonal=132
  53.     EdgeDetect=133
  54.     EmbossHigh=134
  55.     EmbossLow=135
  56.     Focus=136
  57.     FrostedGlass=137
  58.     RaiseHigh=138
  59.     RaiseLow=139
  60.     Shake=140
  61.     SharpenHigh=141
  62.     SharpenLow=142
  63.     Slash=143
  64.     Smooth=144
  65.     Texture=145
  66.  
  67. ; TCP_Write sends as much as possible data to the socket to fasten up the.
  68. ; transfer speed. And you can use it like the write() from Dos.library
  69.     
  70. TCP_Write[d0,a0,d1,d2]:
  71.     {* StackFrame wr,Socket=d0,msg=a0,MsgLen=d1,flags=d2*}
  72.     While (Wr=TCP_Send(Socket,msg,msglen,flags))#msglen
  73.       {
  74.         if wr<1 
  75.          {
  76.            {* UnFramereturn -1*}
  77.          }
  78.         Msg==Msg+Wr
  79.         Msglen==MsgLen-Wr
  80.       }
  81.     {* UnFrameReturn *}
  82.  
  83. ; recv is a timedepended socket-read, this is usefull for nonblocking
  84. ; sockets!
  85.  
  86. recv[d0,d1,d2,d3]:
  87.     {* Stackframe Socket=d0,Zeiger=d1,Laenge=d2,time=d3,Readlen*}
  88.     While Time>0
  89.      {
  90.       Readlen=TCP_recv(Socket,Zeiger,Laenge,0)
  91.       If Readlen>0 breakwhile
  92.       Time==Time-25
  93.       Delay(25)
  94.      }
  95.     {* UnFrameReturn Readlen*}
  96.  
  97. TCP_Sendfile[a0,d0]:
  98.     {* StackFrame Filehandle=#0,Socket=d0,Name=a0,Puffer,Len,Rl*}
  99.     IF (Puffer=Allocmem(200,#MEMF_Fast))=0
  100.      {
  101.       Printf("Conv hat keinen Speicher mehr\n")
  102.       {* UnframeReturn 0*}
  103.      }
  104.     {* FLUSH *}
  105.     If (Filehandle=Open(Name,Mode_old))=0
  106.      {
  107.       Printf("Conv kann file nicht oeffnen\n")
  108.       Freemem(Puffer,200)
  109.       {* UnframeReturn 0*}
  110.      }
  111.     Seek(Filehandle,0,offset_end)
  112.     Len=Seek(Filehandle,0,offset_begin)
  113.     While Len>0
  114.      {
  115.        Rl=Read(Filehandle,Puffer,200)
  116.        If TCP_Write(Socket,Puffer,rl,0)<1 breakwhile
  117.        LEN==LEN-RL
  118.      }
  119.     Close(Filehandle)
  120.     Freemem(Puffer,200)
  121.     {* UnFrameReturn 0*}
  122.  
  123. ; TCP_Getfile sets the socket to blocking to wait for the converted
  124. ; image. Because we don`t know how much time it takes to convert it,
  125. ; we have to wait for ever or a CTRL-C is send to the task, which
  126. ; causes miami to quit this operation.
  127. ; If convd can`t open the converted file for any reason , you get a 
  128. ; errormessage back. (42 chars) . Check this and you know if it
  129. ; worked.
  130.  
  131. TCP_Getfile[a0,d0]:
  132.     {* StackFrame Filehandle=#0,Socket=d0,Name=a0,Puffer,Len,Rl*}
  133.     IF (Puffer=Allocmem(200,#MEMF_Fast))=0
  134.      {
  135.       Printf("Conv hat keinen Speicher mehr\n")
  136.       {* UnframeReturn 0*}
  137.      }
  138.     {* FLUSH *}
  139.     If (Filehandle=Open(Name,Mode_new))=0
  140.      {
  141.       Freemem(Puffer,200)
  142.       Printf("Conv kann File nicht oeffnen\n")
  143.       {* UnframeReturn 0*}
  144.      }
  145.     {* FLUSH *}
  146.     TCP_IoCtlSocket(Socket,FIONBIO,>FIONBIONBTags:0,0)
  147.     Rl=TCP_recv(Socket,Puffer,4,0)
  148.     TCP_IoCtlSocket(Socket,FIONBIO,#FIONBIOTags)
  149.     Printf("Receiving data...\n")
  150.     Write(Filehandle,Puffer,rl)
  151.     While RL>0
  152.      {
  153.        Rl=recv(Socket,Puffer,200,500)
  154.        Write(Filehandle,Puffer,rl)
  155.      }
  156.     Close(Filehandle)
  157.     Freemem(Puffer,200)
  158.     {* UnFrameReturn 0*}
  159.  
  160. Start:
  161.     OH=output()
  162.     Printf("Conv2 gestartet\n")
  163.     If (socket=TCP_Socket(AF_INET,SOCK_STREAM,0))#-1
  164.      {
  165.         If (he=TCP_gethostbyname("localhost"))#0
  166.          {
  167.           Printf("Hostname ok...\n")
  168.  
  169. ; fill out the sockaddr for a TCP-connection to port 24001
  170. ; which is the normal operation port of convd 1.01
  171.  
  172.           #AF_Inet=>sockaddr_in.sin_family
  173.           #24001=>sockaddr_in.sin_port
  174.           Zeiger=.lhostent.H_addr_list(he)
  175.           addr==(Zeiger)
  176.           addr==(Addr)
  177.           addr=>sockaddr_in.sin_addr
  178.           ret=TCP_Connect(Socket,&Sockaddr_in,sizeof(sockaddr_in))
  179.           If ret#-1
  180.            {
  181.              printf("Connected...\n")
  182.              If TCP_IoCtlSocket(Socket,FIONBIO,>FIONBIOTags:1,0)=-1
  183.               {
  184.                TCP_Errno()
  185.               }
  186. ; Set a JPEG as destinationformat  
  187. ; Scale it to a size of 500 x 600 pixel
  188. ; give it 16 M colors at the end!
  189. ; Roll it first 30 pixels to the right.
  190. ; get a negative
  191. ; Smooth it!
  192. ; the other 2 actionfields are free (-1).
  193.  
  194.              #"JPEG"=>Scaleoperators.type
  195.              #500=>Scaleoperators.XPixel
  196.              #600=>Scaleoperators.YPixel
  197.              #257=>Scaleoperators.Colors
  198.              #ROLLX=>Scaleoperators.aktion1
  199.              #30=>Scaleoperators.data1
  200.              #NEGATIVE=>Scaleoperators.Aktion2
  201.              #0=>Scaleoperators.data2
  202.              #SMOOTH=>Scaleoperators.Aktion3
  203.              #0=>Scaleoperators.data3
  204.              #0=>Scaleoperators.data4
  205.              #0=>Scaleoperators.data5
  206.              #-1=>Scaleoperators.Aktion4
  207.              #-1=>Scaleoperators.Aktion5
  208.  
  209. ; Open picturefile "Pics:Clown_sm.gif" 
  210.  
  211.              If (Filehandle=Open("pics:clown_sm.gif",#Mode_old))#0
  212.               { 
  213.  
  214. ; get size of file
  215.  
  216.                 seek(Filehandle,0,offset_end)
  217.                 len=seek(Filehandle,0,offset_begin)
  218.                 Close(Filehandle)
  219.                 TCP_Write(Socket,&len,4,0)
  220.  
  221. ; tell convd that`s a structure comes
  222.  
  223.                 TCP_Write(Socket,"STAT",4,0)
  224.                 TCP_Write(Socket,&Scaleoperators,sizeof(scaleoperators),0)
  225.  
  226. ; send the picture to the demon
  227.  
  228.                 TCP_SendFile("pics:clown_sm.gif",Socket)
  229.                 printf("File send...\nWaiting for file\n")
  230.  
  231. ; get the result 
  232.  
  233.                 TCP_GetFile("ram:test",Socket)
  234.                 printf("Got file\n")
  235.               }
  236.            }
  237.          
  238.          }
  239.       {* FLUSH *}
  240.       Printf("Conv beendet sich jetzt\n")
  241.       TCP_CloseSocket(Socket)
  242.      }
  243.     {* Return *}
  244.  
  245.  
  246. CountString:
  247.         move.l a1,-(Sp)
  248.         move.l a0,a1
  249. .l1:    cmpi.b #$00,(a1)+
  250.         bne .l1
  251.         lea -1(a1),a1
  252.         sub.l a0,a1
  253.         move.l a1,d0
  254.         move.l (sp)+,a1
  255.         RTS
  256.  
  257.